package com.ruoyi.ftrl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.ftrl.domain.Dto.DateDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ftrl.domain.Weather;
import com.ruoyi.ftrl.service.IWeatherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实时天气预报Controller
 * 
 * @author dihang
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/ftrl/weathers")
public class WeatherController extends BaseController
{
    @Autowired
    private IWeatherService weatherService;

    /**
     * 查询实时天气
     */
    @Anonymous
    @GetMapping(value = "/actual")
    public AjaxResult getInfo()
    {
        return success(weatherService.selectWeatherByIdActual());
    }


    /**
     * 获取昨天、今天以及未来两天的天气预报
     */
    @Anonymous
    @GetMapping("/future")
    public Object futureWeather()
    {
    Object object=weatherService.selectWeatherListFuture();
        return object;
    }

    /**
     * 平均室外温度历史曲线(保定市整体地区)
     */
    @GetMapping("/curve")
    public AjaxResult curveHistory(DateDto dateDto)
    {

        return success(weatherService.selectWeatherListCurve(dateDto));
    }



    /**
     * 定时拉取实时天气预报并数据入库
     */
    @GetMapping("/fetch")
    public String fetchWeather() {
        return weatherService.fetchAndSaveWeather();
    }

    /**
     * 查询实时天气预报列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:weathers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Weather weather)
    {
        startPage();
        List<Weather> list = weatherService.selectWeatherList(weather);
        return getDataTable(list);
    }

    /**
     * 导出实时天气预报列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:weathers:export')")
    @Log(title = "实时天气预报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Weather weather)
    {
        List<Weather> list = weatherService.selectWeatherList(weather);
        ExcelUtil<Weather> util = new ExcelUtil<Weather>(Weather.class);
        util.exportExcel(response, list, "实时天气预报数据");
    }

    /**
     * 获取实时天气预报详细信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:weathers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(weatherService.selectWeatherById(id));
    }

    /**
     * 新增实时天气预报
     */
    @PreAuthorize("@ss.hasPermi('ftrl:weathers:add')")
    @Log(title = "实时天气预报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Weather weather)
    {
        return toAjax(weatherService.insertWeather(weather));
    }

    /**
     * 修改实时天气预报
     */
    @PreAuthorize("@ss.hasPermi('ftrl:weathers:edit')")
    @Log(title = "实时天气预报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Weather weather)
    {
        return toAjax(weatherService.updateWeather(weather));
    }

    /**
     * 删除实时天气预报
     */
    @PreAuthorize("@ss.hasPermi('ftrl:weathers:remove')")
    @Log(title = "实时天气预报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weatherService.deleteWeatherByIds(ids));
    }
}
